import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace SettlementRecordApi {
  /** 统一结算记录信息 */
  export interface SettlementRecord {
    id: number; // 主键ID
    groupId: number; // 集团ID
    storeId: number; // 门店ID
    settlementCode?: string; // 结算编码
    settlementType?: string; // 结算类型：consumption-消费结算，recharge-充值，refund-退款，adjustment-调整
    accountId?: number; // 结算账户ID
    customerId?: number; // 客户ID
    consumptionIds: string; // 关联的消费登记ID列表
    consumptionCount: number; // 消费项目数量
    totalAmount?: number; // 总金额
    discountAmount: number; // 优惠金额
    actualAmount?: number; // 实付金额
    paymentMethod: string; // 支付方式：cash-现金，card-银行卡，wechat-微信，alipay-支付宝，balance-余额
    paymentStatus: string; // 支付状态：pending-待支付，paid-已支付，failed-支付失败
    paymentTime: string | Dayjs; // 支付时间
    transactionId: string; // 第三方交易流水号
    settlementStatus: string; // 结算状态：pending-待结算，completed-已完成，cancelled-已取消
    settlementTime: string | Dayjs; // 结算时间
  }
}

/** 查询统一结算记录分页 */
export function getSettlementRecordPage(params: PageParam) {
  return requestClient.get<PageResult<SettlementRecordApi.SettlementRecord>>('/spa/settlement-record/page', { params });
}

/** 查询统一结算记录详情 */
export function getSettlementRecord(id: number) {
  return requestClient.get<SettlementRecordApi.SettlementRecord>(`/spa/settlement-record/get?id=${id}`);
}

/** 新增统一结算记录 */
export function createSettlementRecord(data: SettlementRecordApi.SettlementRecord) {
  return requestClient.post('/spa/settlement-record/create', data);
}

/** 修改统一结算记录 */
export function updateSettlementRecord(data: SettlementRecordApi.SettlementRecord) {
  return requestClient.put('/spa/settlement-record/update', data);
}

/** 删除统一结算记录 */
export function deleteSettlementRecord(id: number) {
  return requestClient.delete(`/spa/settlement-record/delete?id=${id}`);
}


/** 导出统一结算记录 */
export function exportSettlementRecord(params: any) {
  return requestClient.download('/spa/settlement-record/export-excel', { params });
}

